<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>移除元素</title>
  </head>
  <body>
    <script>
      var removeElement = function (num, val) {
        while (num.indexOf(val) !== -1) {
          num.splice(num.indexOf(val), 1);
        }
        return num.length;
      };
      var num = [0, 1, 2, 2, 3, 0, 4, 2];
      console.log(removeElement(num, 2));
      console.log(num);
    </script>
  </body>
</html>
